﻿using System;
using System.Runtime.InteropServices;//必须引用此项
using System.Windows.Forms;

namespace WindowsApplication2.图形_声音_视频.Api
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Title = "选择文件...";

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.textBox2.Text = dlg.FileName;
            }
        }

        //只支持wav文件
        [DllImport("winmm.dll", EntryPoint = "sndPlaySound")]
        public static extern int sndPlaySound(
                string lpszSoundName,
                int uFlags
        );

        private void button1_Click(object sender, EventArgs e)
        {
            sndPlaySound(this.textBox2.Text, 0);
        }
    }
}